package com.lesent.kafka.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.lesent.kafka.service.IKafkaService;
import com.lesent.model.entity.Student;
import com.lesent.model.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author shengtao
 * @Description:
 * @date 2018/08/14 15:27
 */
@Slf4j
@RestController
@RequestMapping("/kafka")
public class KafkaController {

    @Autowired
    private IKafkaService kafkaService;

    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity kafkaSend() {
        Map<String, Student> map = new HashMap<>();
        Student student = new Student("李胜涛", 22, "打球");
        map.put(student.getName(), student);
        List<String> result = kafkaService.sendMsg("kafka-test", map);
        log.info("result :{}", result.stream().collect(Collectors.joining(",")));
        return ResponseEntity.ok(result);
    }

}
